<script setup lang="ts">
import { ref } from "vue";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import Refresh from "@iconify-icons/ep/refresh";
import AddFill from "@iconify-icons/ri/add-circle-line";
import EditPen from "@iconify-icons/ep/edit-pen";
import More from "@iconify-icons/ep/more-filled";
import Delete from "@iconify-icons/ep/delete";
import { useRoute } from "vue-router";
import { useRole } from "./utils/hook";
import { PureTableBar } from "@/components/RePureTableBar";
const treeRef = ref();
const formRef = ref();
const tableRef = ref();
const {
  form,
  loading,
  columns,
  dataList,
  pag,
  buttonClass,
  resetDialog,
  pagination,
  onSearch,
  resetForm1,
  openDialog,
  handleUpdate,
  handleDelete,
  handleSizeChange,
  allCustomer,
  handleCurrentChange
} = useRole(tableRef, treeRef);
defineOptions({
  name: "invoiceManage"
});
</script>

<template>
  <div>
    <el-form
      ref="formRef"
      :inline="true"
      :model="pag"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto"
    >
      <el-form-item label="用户名称：" prop="customerId">
        <el-input
          v-model="pag.customerId"
          placeholder="请输用户名称"
          clearable
          class="!w-[180px]"
        />
      </el-form-item>
      <!-- <el-form-item label="用户手机号：" prop="mobile">
        <el-input
          v-model="pag.mobile"
          placeholder="请输入用户手机号"
          clearable
          class="!w-[180px]"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ri:search-line')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm1(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>
    <!-- 下面的内容 -->
    <PureTableBar title="用户列表 " :columns="columns" @refresh="onSearch">
      <template #buttons>
        <el-button
          type="primary"
          :icon="useRenderIcon(AddFill)"
          @click="openDialog()"
        >
          添加用户
        </el-button>
      </template>

      <template v-slot="{ size, dynamicColumns }">
        <pure-table
          ref="tableRef"
          row-key="id"
          adaptive
          :adaptiveConfig="{ offsetBottom: 108 }"
          align-whole="center"
          table-layout="auto"
          :loading="loading"
          :size="size"
          :data="dataList"
          :columns="dynamicColumns"
          :pagination="{ ...pagination, size }"
          :header-cell-style="{
            background: 'var(--el-fill-color-light)',
            color: 'var(--el-text-color-primary)'
          }"
          @page-size-change="handleSizeChange"
          @page-current-change="handleCurrentChange"
        >
          <template #operation="{ row }">
            <el-button
              :disabled="row.userName == 'admin'"
              class="reset-margin"
              link
              :size="size"
              type="primary"
              @click="resetDialog(row)"
            >
              重置密码
            </el-button>
            <el-button
              class="reset-margin"
              link
              :size="size"
              type="primary"
              @click="openDialog('修改', row)"
            >
              修改
            </el-button>
            <el-popconfirm
              :title="`是否确认删除用户名为${row.userName}的这条数据`"
              @confirm="handleDelete(row)"
            >
              <template #reference>
                <el-button
                  class="reset-margin"
                  link
                  type="primary"
                  :size="size"
                >
                  删除
                </el-button>
              </template>
            </el-popconfirm>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<style lang="scss" scoped>
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}

.main-content {
  margin: 24px 24px 0 !important;
}

.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
</style>
